#include "taskQueue.h"
#include "ThreadPool.h"

int taskQueueInit(taskQueue_t *pqueue){
    bzero(pqueue, sizeof(taskQueue_t));
    return 0;
}

int enQueue(taskQueue_t *pqueue, int netFd, int ptaskCode, MYSQL **sqlconn, const char* userName, const char* userPasswd){
    //尾插法入队
    node_t *pNew = (node_t *)calloc(1, sizeof(node_t));
    pNew->netFd = netFd;
    pNew->taskCode = ptaskCode;
    pNew->conn = *sqlconn;
    memcpy(pNew->userName, userName, sizeof(userName));
    memcpy(pNew->userPasswd, userPasswd, sizeof(userPasswd));
    if(0 == pqueue->queueSize){
        pqueue->pFront = pNew;
        pqueue->pRear = pNew;
    }
    else{
        pqueue->pRear->pNext = pNew->pNext;
        pqueue->pRear = pNew;
    }
    ++pqueue->queueSize;
    return 0;
}

int deQueue(taskQueue_t *pqueue){
    //头部元素出队
    node_t *pCur = pqueue->pFront;
    pqueue->pFront = pCur->pNext;
    if(1 == pqueue->queueSize){
        pqueue->pRear = NULL;
    }
    --pqueue->queueSize;
    free(pCur);
    return 0;
}